import { IsShowConsole } from "../配置/基础配置";
import { getInsertSql } from "./dbUtil";

export enum LogType {
    None = '',
    System = "系统",
    SystemError = "系统错误",
    Die = "死亡",
    FreshMon = "刷怪",
    Slave = "宝宝",
    Map = "地图",
    MonItem = "怪物爆物",
    MonItemError = "怪物爆物出错"
}

export function saveLog(message: string, type?: LogType, from?: TActor, to?: TActor) {
    type = type || LogType.None
    let time = DateUtils.FormatDateTime('yyyy-mm-dd hh-nn-ss', DateUtils.Now())
    if (IsShowConsole) {
        console.log(message)
    }
    let fromStr = from?.Name || ''
    let toStr = to?.Name || ''
    let sql = getInsertSql('mirLog', ['time', 'type', 'message', 'server', '`from`', '`to`'],
        [time, type, message, GameLib.ServerName, fromStr, toStr])

    return GameLib.DBEngine.ExecSQL('数据库', sql)

}

export function deleteLog() {
    let date: number = DateUtils.IncDay(DateUtils.Now(), -4)
    let time = DateUtils.FormatDateTime('YYYY-MM-DD HH:mm:ss', date)
    let sql = `delete from mirLog where time<'${time}'`
    return GameLib.DBEngine.ExecSQL('数据库', sql)
}


